/*
* 地图块;
*/
    /**x方向切割数量 */
class MapTile{
    private  _row:number;
    /**y方向切割数量 */
    private  _col:number;
    /**资源路径 */
    private  _resUrl:string;
    /**是否加载完成 */
    private  _isLoaded:Boolean = false;
    /**是否加载进行 */
    private  _isLoading:Boolean = false;
    /**显示对象 */
    private  _disObj:Sprite;
    /**父对象 */
    private  _parent:Sprite;
    private _loadEndHander:Laya.Handler;
    private _loadingHander:Laya.Handler;

    /**
     *  构造函数  
     * @param row x方向切割数量
     * @param col y方向切割数量
     * @param parent 父容器
     */
    constructor(col:number,row:number,parent:Sprite){
        this._row = row;
        this._col = col;
        this._parent = parent;
        this._resUrl = "res/map/map_001/" + col + "_" +  row+ ".jpg";//切割命名方式X_Y
        this._disObj = new Sprite();
    }

    public loadTile():void
    {
        this._loadEndHander = Laya.Handler.create(this,this.onComplete);
        Laya.loader.load(this._resUrl,this._loadEndHander)
    }

    /**
     * 资源加载完成
     */
    private onComplete():void
    {
        if (this._loadEndHander)  {
            this._loadEndHander.recover();
        }
        this._isLoaded = true;
        this._isLoading = false;
        // let txture:Laya.Texture = Laya.loader.getRes(this._resUrl);
        // this._disObj.graphics.drawTexture(txture,0,0);
        this._disObj.texture = Laya.loader.getRes(this._resUrl);
        // SelfPlayer.instance.disObj.x
        this._disObj.x = this._row * 300;
        this._disObj.y = this._col * 300;
        this._parent.addChild(this._disObj)
    }

    public dispose():void
    {
        this._disObj.graphics.clear();
        if(this._isLoading)
        {
            Laya.loader.cancelLoadByUrl(this._resUrl);
            this._isLoading = false;
        }else
        {
            Laya.loader.clearRes(this._resUrl,true)
        }
        this._isLoaded = false;
        this._parent.removeChild(this._disObj)
    }
}